<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yuanzhiying.github.io","root":"/","images":"/images","scheme":"Gemini","version":"8.1.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta name="description" content="坚持下去">
<meta property="og:type" content="website">
<meta property="og:title" content="yuanzhiying的博客">
<meta property="og:url" content="http://yuanzhiying.github.io/index.html">
<meta property="og:site_name" content="yuanzhiying的博客">
<meta property="og:description" content="坚持下去">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="yuanzhiying">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://yuanzhiying.github.io/">


<script data-pjax class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>
<title>yuanzhiying的博客</title>
  



  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="yuanzhiying的博客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">yuanzhiying的博客</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">工作学习记录</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">4</span></a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">7</span></a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">9</span></a></li>
        <li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <section class="post-toc-wrap sidebar-panel">
        </section>
        <!--/noindex-->

        <section class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">yuanzhiying</p>
  <div class="site-description" itemprop="description">坚持下去</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">9</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/yuanzhiying" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yuanzhiying" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



        </section>
      </div>
        <div class="back-to-top animated">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2021/01/26/Swift%E4%B8%ADassociatedtype/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/01/26/Swift%E4%B8%ADassociatedtype/" class="post-title-link" itemprop="url">Swift中associatedtype</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2021-01-26 11:35:11 / 修改时间：13:52:41" itemprop="dateCreated datePublished" datetime="2021-01-26T11:35:11+08:00">2021-01-26</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Swift/" itemprop="url" rel="index"><span itemprop="name">Swift</span></a>
        </span>
    </span>

  
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>933</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; associatedtype定义关联类型，相当于类型的占位符，让实现协议的类型来指定具体的类型</span><br><span class="line"></span><br><span class="line">protocol Food &#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">protocol Animal &#123;</span><br><span class="line">    associatedtype F: Food</span><br><span class="line">    func eat(_ food: F)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">struct Meat: Food &#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">struct Grass: Food &#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">struct Tiger: Animal &#123;</span><br><span class="line">    func eat(_ food: Meat) &#123;</span><br><span class="line">        print(&quot;eat \(food)&quot;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">struct Sheep: Animal &#123;</span><br><span class="line">    func eat(_ food: Grass) &#123;</span><br><span class="line">        print(&quot;eat \(food)&quot;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">func test() &#123;</span><br><span class="line">    let tiger &#x3D; Tiger()</span><br><span class="line">    tiger.eat(Meat())</span><br><span class="line"></span><br><span class="line">    let sheep &#x3D; Sheep()</span><br><span class="line">    sheep.eat(Grass())</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#x2F;*</span><br><span class="line"></span><br><span class="line">Protocol &#39;Animal&#39; can only be used as a generic constraint because it has Self or associated type requirements</span><br><span class="line">只能被用作泛型约束，不能当做独立的类型使用</span><br><span class="line"> </span><br><span class="line">错误代码：</span><br><span class="line">func isTiger(animal: Animal) -&gt; Bool &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">*&#x2F;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 具有关联类型的协议类型，只能当做泛型约束使用</span><br><span class="line">func isTiger&lt;A: Animal&gt;(animal: A) -&gt; Bool &#123;</span><br><span class="line">    if animal is Tiger &#123;</span><br><span class="line">        return true</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        return false</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      


    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2021/01/22/SwiftUI%E4%B8%8E%E5%8E%9F%E9%A1%B9%E7%9B%AE%E6%B7%B7%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/01/22/SwiftUI%E4%B8%8E%E5%8E%9F%E9%A1%B9%E7%9B%AE%E6%B7%B7%E7%94%A8/" class="post-title-link" itemprop="url">SwiftUI与原项目混用</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-01-22 13:33:45" itemprop="dateCreated datePublished" datetime="2021-01-22T13:33:45+08:00">2021-01-22</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-01-26 13:52:41" itemprop="dateModified" datetime="2021-01-26T13:52:41+08:00">2021-01-26</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Swift/" itemprop="url" rel="index"><span itemprop="name">Swift</span></a>
        </span>
    </span>

  
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>308</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p><code>Swift</code>跳转到<code>SwiftUI</code>；以<code>Push</code>为例，<code>present</code>一样的，只不过是需要用<code>UIHostingController</code>初始化你的<code>SwiftUIView</code>。初始化出来的就是一个正常的<code>UIViewController</code>，正儿八经的控制器，怎么用都行。</p>
<p>示例代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">if #available(iOS 13, *) &#123;</span><br><span class="line">            let testSwiftUIView &#x3D; UIHostingController(rootView: TestSwiftUIView())</span><br><span class="line">            navigationController?.pushViewController(testSwiftUIView, animated: true)</span><br><span class="line"></span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      


    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2021/01/14/SwiftUI%E5%AD%A6%E4%B9%A0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/01/14/SwiftUI%E5%AD%A6%E4%B9%A0/" class="post-title-link" itemprop="url">SwiftUI学习</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-01-14 09:51:25" itemprop="dateCreated datePublished" datetime="2021-01-14T09:51:25+08:00">2021-01-14</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-01-26 13:52:41" itemprop="dateModified" datetime="2021-01-26T13:52:41+08:00">2021-01-26</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Swift/" itemprop="url" rel="index"><span itemprop="name">Swift</span></a>
        </span>
    </span>

  
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>6.6k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>6 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>学习文章：<br><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_33701617/article/details/93164551?utm_medium=distribute.pc_relevant.none-task-blog-searchFromBaidu-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-searchFromBaidu-2.control">SwiftUI对比Flutter</a><br><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/343549752">八个常见的SwiftUI误用及对应的正确打开方式</a><br><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/8d5e0f80856b">SwiftUI 基础之 Identifiable</a><br><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/a2a69fb070b0">SwiftUI - Data Binding注解</a></p>
<ul>
<li><code>SwiftUI</code>要求</li>
</ul>
<ol>
<li>iOS13.0+</li>
</ol>
<h6 id="快捷键"><a href="#快捷键" class="headerlink" title="快捷键"></a>快捷键</h6><ol>
<li>control + option + 点击：出现属性编辑器</li>
<li>command + 点击：出现快捷菜单</li>
</ol>
<h6 id="布局"><a href="#布局" class="headerlink" title="布局"></a>布局</h6><ol>
<li>VStack - 垂直布局</li>
<li>HStack - 水平布局</li>
<li>Spacer - 间距</li>
<li>Text - 文本</li>
<li>Image - 图片</li>
<li>Divider - 分割线</li>
<li>Group - 预览窗口预览多个</li>
<li>ScrollView - 滚动视图</li>
<li>Path - 路径</li>
<li>Shaper - 形状</li>
</ol>
<h6 id="代码解析"><a href="#代码解析" class="headerlink" title="代码解析"></a>代码解析</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">struct ContentView: View &#123;</span><br><span class="line">    var body: some View &#123;</span><br><span class="line">        Text(&quot;Hello, world!&quot;)</span><br><span class="line">            .font(.title)</span><br><span class="line">            .foregroundColor(.yellow)</span><br><span class="line">            .bold()</span><br><span class="line">            .italic()</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">struct ContentView_Previews: PreviewProvider &#123;</span><br><span class="line">    static var previews: some View &#123;</span><br><span class="line">        ContentView()</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ol>
<li><code>ContentView</code>为布局，<code>ContentView_Previews</code>为预览布局</li>
<li><code>body</code>为计算属性，类型为不透明类型的<code>View</code>，不透明类型使用<code>some</code>修饰</li>
<li><code>Swift</code>语法，只有一行代码，<code>return</code>可以省略</li>
<li><code>some</code>修饰，表示不透明类型，总会返回某一个特定的类型，但是不知道是哪一种<blockquote>
<ol>
<li>可以返回关联类型的协议类型</li>
<li>安全性：不对外暴露具体的返回类型</li>
<li>用来解决<code>SwiftUI</code>繁琐的不确定返回类型问题</li>
</ol>
</blockquote>
</li>
</ol>
<h6 id="使用技巧"><a href="#使用技巧" class="headerlink" title="使用技巧"></a>使用技巧</h6><ol>
<li><p>可以在右上角+里拖动空间到代码中</p>
</li>
<li><p>使用<code>import</code>导入所需的库</p>
</li>
<li><p>可以新建<code>SwiftUI View</code></p>
</li>
<li><p><code>ignoresSafeArea</code>忽略<code>safeArea</code>的边距，用在<code>feame</code>前</p>
</li>
<li><p>布局group组件可增加<code>padding</code></p>
</li>
<li><p><code>VStack</code>可添加<code>font</code>、<code>foregroundColor</code>等属性，对所有包含的元素起效</p>
</li>
<li><p>串联属性，每一个点语法属性，返回当前对象</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Text(&quot;Hello world!&quot;)</span><br><span class="line">   .font(.title)</span><br><span class="line">   .foregroundColor(.purple)</span><br><span class="line">   </span><br><span class="line">A modifier returns a view that applies a new behavior or visual change. You can chain multiple modifiers to achieve the effects you need.</span><br></pre></td></tr></table></figure></li>
<li><p>使用<code>previewLayout</code>可以定义预览的窗口的大小，也可以使用<code>Group</code>同时预览多个窗口，通用属性可以提取到外面</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">struct LandmarkRow_Previews: PreviewProvider &#123;</span><br><span class="line">    static var previews: some View &#123;</span><br><span class="line">        Group &#123;</span><br><span class="line">            LandmarkRow(landmark: landmarks[0])</span><br><span class="line">            LandmarkRow(landmark: landmarks[1])</span><br><span class="line">        &#125;</span><br><span class="line">        .previewLayout(.fixed(width: 300, height: 70))</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p><code>Identifiable</code>：作为唯一标识<br>遍历需要唯一标识来遍历，如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">List(landmarks, id: \.id) &#123; landmark in</span><br><span class="line">    NavigationLink(</span><br><span class="line">        destination: LandmarkDetail()) &#123;</span><br><span class="line">        LandmarkRow(landmark: landmark)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>如果让列表中元素遵守<code>Identifiable</code>协议，遍历处即可省略<code>id</code>参数，model中需要有名称为<code>id</code>的属性</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">struct Landmark: Hashable, Codable, Identifiable &#123;</span><br><span class="line">    var id: Int</span><br><span class="line">    var name: String</span><br></pre></td></tr></table></figure></li>
<li><p>页面跳转使用<code>NavigationLink</code>，<code>destination</code>为要跳转的页面</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">NavigationLink(destination: LandmarkDetail()) &#123;</span><br><span class="line">    LandmarkRow(landmark: landmark)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>使用<code>NavigationView</code>为页面田健导航栏，可设置 <code>navigationTitle</code>等</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">NavigationView &#123;</span><br><span class="line">    List(landmarks) &#123; landmark in</span><br><span class="line">        NavigationLink(destination: LandmarkDetail()) &#123;</span><br><span class="line">            LandmarkRow(landmark: landmark)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    .navigationTitle(&quot;Landmarks&quot;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>预览窗口按钮作用：<br>第一个按钮：<code>Live Preview</code> 和<code>Debug Preview</code>，未打开只能查看页面，不能点击等，打开之后可以点击跳转页面等交互操作<br>第二个按钮：<code>Preview On Device</code>，连上真机点击之后，预览可以同步在真机上展示<br>第三个按钮：<code>Inspect Preview</code>，可以打开窗口属性窗口，可以设置预览窗口属性<br>第四个按钮：<code>Duplicate Preview</code> ，可以复制创建多个预览窗口</p>
</li>
<li><p>代码控制预览的机型</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">struct LandmarkList_Previews: PreviewProvider &#123;</span><br><span class="line">    static var previews: some View &#123;</span><br><span class="line">        LandmarkList()</span><br><span class="line">            .previewDevice(PreviewDevice(rawValue: &quot;iPhone SE (2nd generation)&quot;))</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 多设备同时预览</span><br><span class="line">struct LandmarkList_Previews: PreviewProvider &#123;</span><br><span class="line">    static var previews: some View &#123;</span><br><span class="line">        ForEach([&quot;iPhone 8&quot;, &quot;iPhone 12 Pro Max&quot;], id: \.self) &#123; deviceName in</span><br><span class="line">            LandmarkList()</span><br><span class="line">                .previewDevice(PreviewDevice(rawValue: deviceName))</span><br><span class="line">                .previewDisplayName(deviceName)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>组合静态的<code>View</code>和动态的<code>view</code>到<code>List</code>里，可使用<code>List + ForEach</code>：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">List(filteredLandmarks) &#123; landmark in</span><br><span class="line">    NavigationLink(destination: LandmarkDetail(landmark: landmark)) &#123;</span><br><span class="line">        LandmarkRow(landmark: landmark)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">替换为</span><br><span class="line"></span><br><span class="line">List &#123;</span><br><span class="line">    Toggle(isOn: $showFavoriteOnly) &#123;</span><br><span class="line">        Text(&quot;Favorites only&quot;)</span><br><span class="line">    &#125;</span><br><span class="line">    ForEach(filteredLandmarks) &#123; landmark in</span><br><span class="line">        NavigationLink(destination: LandmarkDetail(landmark: landmark)) &#123;</span><br><span class="line">            LandmarkRow(landmark: landmark)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>如果遍历的对象没有实现<code>Identifiable</code>协议，则需要传<code>id</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">List &#123;</span><br><span class="line">    ForEach(modelData.categories.keys.sorted(), id: \.self) &#123; key in</span><br><span class="line">        Text(key)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p><code>ObservableObject</code>协议<br>当遵守<code>ObservableObject</code>协议的数据更新时，绑定数据的<code>view</code>会自动更新</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">final class ModelData: ObservableObject &#123;</span><br><span class="line">    @Published var landmarks: [Landmark] &#x3D; load(&quot;landmarkData.json&quot;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><code>@Published</code><br>使用<code>@Published</code>修饰监听对象的属性，表示该对象的属性需要把属性值的改变更新进去</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">final class ModelData: ObservableObject &#123;</span><br><span class="line">    @Published var landmarks: [Landmark] &#x3D; load(&quot;landmarkData.json&quot;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p><code>@StateObject</code><br>使用<code>@StateObject</code>初始化一个监听对象的数据，<br>使用<code>.environmentObject</code>把数据设置到环境对象里，<br>在需要的地方去取环境对象<code>@EnvironmentObject var modelData: ModelData</code>进行使用</p>
</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">@main</span><br><span class="line">struct MySwiftUIApp: App &#123;</span><br><span class="line">    &#x2F;&#x2F; 定义</span><br><span class="line">    @StateObject private var modelData &#x3D; ModelData()</span><br><span class="line">    </span><br><span class="line">    var body: some Scene &#123;</span><br><span class="line">        WindowGroup &#123;</span><br><span class="line">            ContentView()</span><br><span class="line">            &#x2F;&#x2F; 设置</span><br><span class="line">                .environmentObject(modelData)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 取</span><br><span class="line">@EnvironmentObject var modelData: ModelData</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 使用</span><br><span class="line">modelData.landmarks</span><br></pre></td></tr></table></figure>
<ol start="18">
<li><code>Bool</code>的<code>toggle()</code>方法：在<code>true</code>和<code>false</code>之前切换</li>
<li><code>@EnvironmentObject</code>属性用于在下级view中接收传递过来的参数</li>
<li><code>environmentObject(_:) </code>方法用于向下级传递参数</li>
<li><code>@Binding</code>：绑定修饰符用于修饰一个值，这个值用来改变另外一个值<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">绑定：</span><br><span class="line">@Binding var isSet: Bool</span><br><span class="line"></span><br><span class="line">修改：</span><br><span class="line">FavoriteButton(isSet: $modelData.landmarks[landmarkIndex].isFavorite)</span><br></pre></td></tr></table></figure></li>
<li>定义有状态的字段，使用<code>@State</code>修饰，定义为<code>private</code>，并且赋初始值<br><code>@State private var showFavoritesOnly = false</code></li>
<li><code>@State</code>：<br>使用@State属性为应用程序中的数据建立一个真实来源，您可以从多个视图中修改这些数据。SwiftUI管理底层存储并根据值自动更新视图。</li>
<li>使用<code>Path</code>直接绘制，可以当做View来使用</li>
<li><code>View</code>动画，包括颜色、透明度、旋转、大小和其他属性等，可以使用<code>withAnimation</code>来包裹状态State实现动画<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">withAnimation &#123;</span><br><span class="line">    self.showDetail.toggle()</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">withAnimation(.easeInOut(duration: 4)) &#123;</span><br><span class="line">    self.showDetail.toggle()</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>调用<code>View</code>的<code>transition</code>可以为<code>View</code>添加动画<br><code>HikeDetail(hike: hike).transition(.slide)</code><br>自定义<code>transition</code>可自定义动画<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">extension AnyTransition &#123;</span><br><span class="line">    static var moveAndFade: AnyTransition &#123;</span><br><span class="line">        AnyTransition.slide</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">extension AnyTransition &#123;</span><br><span class="line">    static var moveAndFade: AnyTransition &#123;</span><br><span class="line">        AnyTransition.move(edge: .trailing)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">extension AnyTransition &#123;</span><br><span class="line">    static var moveAndFade: AnyTransition &#123;</span><br><span class="line">        let insertion &#x3D; AnyTransition.move(edge: .trailing).combined(with: .opacity)</span><br><span class="line">        let removal &#x3D; AnyTransition.scale.combined(with: .opacity)</span><br><span class="line">        return .asymmetric(insertion: insertion, removal: removal)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><code>ListRowInsets</code>用来调整一个view在lsit中的上下左右间距</li>
<li><code>CaseIterable</code>，用在<code>enum</code>中用来获取<code>allCases</code>方法</li>
<li><code>@Environment</code>，SwiftUI提供了在环境中值的存储，使用<code>@Environment</code>可以访问值，并可以读写<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">@Environment(\.editMode) var editMode</span><br></pre></td></tr></table></figure></li>
<li><code>@State</code> 、<code>@ObservableObject</code>、<code>@Binding</code>、<code>@EnvironmentObject</code>区别<br>@State和@ObservableObject之间有一些细微的差异。这些都是很重要的，因为它们都有不同的用途。<br>@State在视图本地。值或数据在视图中本地保存。它由框架管理，由于它存储在本地，因此它是一个值类型。<br>@ObservableObject在视图外部，并且不存储在视图中。它是一种引用类型，因为它不在本地存储，而只是具有对该值的引用。这不是由框架自动管理的，而是开发人员的责任。这最适用于外部数据，例如数据库或由代码管理的模型。<br>@Binding也在视图内，但是与@State区别在于@Binding用于不通视图之间的参数传递。@Binding和@ObservedObbjecg一样都是传递引用。<br>@EnvironmentObject 可以理解为全局变量</li>
<li><code>ObservableObject</code>和<code>@Published</code><br>遵循 ObservableObject 协议的类可以使用 SwiftUI 的 @Published 属性包装器来自动发布属性的变化，以便使用该类的实例的任何视图能够自动重新调用 body 属性，保持界面与数据的一致。<br><code>@Published var profile = Profile.default</code><br>界面中使用<code>@Binding</code>来绑定UI<br>``</li>
<li>使用<code>UIViewRepresentable</code>来将<code>UIKit</code>中已有的<code>View</code>在<code>SwiftUI</code>中使用<br>使用<code>UIViewControllerRepresentable</code>来<code>UIKit</code>中的<code>UIViewController</code>在<code>SwiftUI</code>中使用<br><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/384867321b67">UIViewRepresentable</a><br>使用方法如下：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">import SwiftUI</span><br><span class="line">import UIKit</span><br><span class="line"></span><br><span class="line">struct PageControl: UIViewRepresentable &#123;</span><br><span class="line">    var numberOfPages: Int</span><br><span class="line">    @Binding var currentPage: Int</span><br><span class="line">    </span><br><span class="line">    func makeUIView(context: Context) -&gt; UIPageControl &#123;</span><br><span class="line">        let control &#x3D; UIPageControl()</span><br><span class="line">        control.numberOfPages &#x3D; numberOfPages</span><br><span class="line">        return control</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    func updateUIView(_ uiView: UIPageControl, context: Context) &#123;</span><br><span class="line">        uiView.currentPage &#x3D; currentPage</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>

      
    </div>

    
    
    
      


    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2021/01/13/SwiftUI-%E4%B8%AD%E7%9A%84some%E5%85%B3%E9%94%AE%E5%AD%97/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/01/13/SwiftUI-%E4%B8%AD%E7%9A%84some%E5%85%B3%E9%94%AE%E5%AD%97/" class="post-title-link" itemprop="url">SwiftUI 中的some关键字</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-01-13 18:03:43" itemprop="dateCreated datePublished" datetime="2021-01-13T18:03:43+08:00">2021-01-13</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-01-26 13:52:41" itemprop="dateModified" datetime="2021-01-26T13:52:41+08:00">2021-01-26</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Swift/" itemprop="url" rel="index"><span itemprop="name">Swift</span></a>
        </span>
    </span>

  
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>16</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/6eef60ab14bc">SwiftUI 中的some关键字</a></p>

      
    </div>

    
    
    
      


    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2020/12/24/Xcode%E6%B8%85%E9%99%A4%E7%BC%93%E5%AD%98%E7%9B%B8%E5%85%B3%E6%96%87%E4%BB%B6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2020/12/24/Xcode%E6%B8%85%E9%99%A4%E7%BC%93%E5%AD%98%E7%9B%B8%E5%85%B3%E6%96%87%E4%BB%B6/" class="post-title-link" itemprop="url">Xcode清除缓存相关文件</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-12-24 16:34:00" itemprop="dateCreated datePublished" datetime="2020-12-24T16:34:00+08:00">2020-12-24</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-01-26 13:52:41" itemprop="dateModified" datetime="2021-01-26T13:52:41+08:00">2021-01-26</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Mac/" itemprop="url" rel="index"><span itemprop="name">Mac</span></a>
        </span>
    </span>

  
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>479</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>参考文章：<a target="_blank" rel="noopener" href="https://www.jianshu.com/p/9c88b782c6dd">Xcode清除缓存相关文件</a></p>
<h2 id="可删"><a href="#可删" class="headerlink" title="可删"></a>可删</h2><h5 id="1-模拟器运行程序产生的数据-DerivedData-（可删）"><a href="#1-模拟器运行程序产生的数据-DerivedData-（可删）" class="headerlink" title="1. 模拟器运行程序产生的数据(DerivedData)（可删）"></a>1. 模拟器运行程序产生的数据(DerivedData)（可删）</h5><p><code>~/Library/Developer/Xcode/DerivedData</code></p>
<h5 id="2-Xcode打包产生的app-icon历史版本-Products-（可删）"><a href="#2-Xcode打包产生的app-icon历史版本-Products-（可删）" class="headerlink" title="2. Xcode打包产生的app icon历史版本(Products)（可删）"></a>2. Xcode打包产生的app icon历史版本(Products)（可删）</h5><p><code>~/Library/Developer/Xcode/Products/</code></p>
<h5 id="3-XCPGDevices-playground-项目缓存-（可删）"><a href="#3-XCPGDevices-playground-项目缓存-（可删）" class="headerlink" title="3. XCPGDevices(playground 项目缓存)（可删）"></a>3. XCPGDevices(playground 项目缓存)（可删）</h5><p><code>~/Library/Developer/XCPGDevices/</code></p>
<h2 id="选删"><a href="#选删" class="headerlink" title="选删"></a>选删</h2><h5 id="1-Xcode打ipa包的历史记录xcarchive文件（选删）"><a href="#1-Xcode打ipa包的历史记录xcarchive文件（选删）" class="headerlink" title="1. Xcode打ipa包的历史记录xcarchive文件（选删）"></a>1. Xcode打ipa包的历史记录xcarchive文件（选删）</h5><p><code>~/Library/Developer/Xcode/Archives</code></p>
<h5 id="2-设备支持文件-DeviceSupport-（选删）"><a href="#2-设备支持文件-DeviceSupport-（选删）" class="headerlink" title="2. 设备支持文件(DeviceSupport)（选删）"></a>2. 设备支持文件(DeviceSupport)（选删）</h5><p><code>~/Library/Developer/Xcode/iOS DeviceSupport</code></p>
<h5 id="3-证书描述文件（选删）"><a href="#3-证书描述文件（选删）" class="headerlink" title="3. 证书描述文件（选删）"></a>3. 证书描述文件（选删）</h5><p><code>~/Library/MobileDevice/Provisioning Profiles</code></p>
<h5 id="4-模拟器文件（选删）"><a href="#4-模拟器文件（选删）" class="headerlink" title="4. 模拟器文件（选删）"></a>4. 模拟器文件（选删）</h5><p><code>~/Library/Developer/CoreSimulator/Profiles/Devices/</code></p>

      
    </div>

    
    
    
      


    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2020/12/21/iMac%E5%90%88%E5%B9%B6%E8%9E%8D%E5%90%88%E7%A1%AC%E7%9B%98/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2020/12/21/iMac%E5%90%88%E5%B9%B6%E8%9E%8D%E5%90%88%E7%A1%AC%E7%9B%98/" class="post-title-link" itemprop="url">iMac合并融合硬盘</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-12-21 23:46:55" itemprop="dateCreated datePublished" datetime="2020-12-21T23:46:55+08:00">2020-12-21</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-01-26 13:52:41" itemprop="dateModified" datetime="2021-01-26T13:52:41+08:00">2021-01-26</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Mac/" itemprop="url" rel="index"><span itemprop="name">Mac</span></a>
        </span>
    </span>

  
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>394</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>官方文档：<a target="_blank" rel="noopener" href="https://support.apple.com/zh-cn/HT207584">https://support.apple.com/zh-cn/HT207584</a></p>
<h2 id="使用“终端”重新创建融合硬盘"><a href="#使用“终端”重新创建融合硬盘" class="headerlink" title="使用“终端”重新创建融合硬盘 "></a>使用“终端”重新创建融合硬盘 </h2><p>以下步骤将永久删除融合硬盘所含驱动器上储存的所有数据。在继续之前，请确保您进行了<a target="_blank" rel="noopener" href="https://support.apple.com/zh-cn/HT201250">备份</a>。 </p>
<h3 id="如果您使用的是-macOS-Mojave-或更高版本"><a href="#如果您使用的是-macOS-Mojave-或更高版本" class="headerlink" title="如果您使用的是 macOS Mojave 或更高版本"></a>如果您使用的是 macOS Mojave 或更高版本</h3><ol>
<li> 将 Mac 开机，然后立即按住 Command-R 以<a target="_blank" rel="noopener" href="https://support.apple.com/zh-cn/HT201314">通过 macOS 恢复功能启动</a>。在看到 Apple 标志或旋转的地球时松开这些键。</li>
<li> 当您看到“macOS 实用工具”窗口时，请从菜单栏中选取“实用工具”&gt;“终端”。</li>
<li> 在“终端”窗口中键入 <code>diskutil resetFusion</code>，然后按 Return 键。</li>
<li> 在出现提示时键入 <code>Yes</code>（<em>Y</em> 需要大写），然后按 Return 键。</li>
<li> 当“终端”指示操作成功时，退出“终端”以返回“macOS 实用工具”窗口。</li>
<li> 选取“<a target="_blank" rel="noopener" href="https://support.apple.com/zh-cn/HT204904">重新安装 macOS</a>”，然后按照屏幕上的说明操作，以重新安装 Mac 操作系统。完成后，Mac 将从您的融合硬盘重新启动。</li>
</ol>

      
    </div>

    
    
    
      


    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2020/12/16/hexo%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2020/12/16/hexo%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" class="post-title-link" itemprop="url">hexo常用命令</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-12-16 16:12:17" itemprop="dateCreated datePublished" datetime="2020-12-16T16:12:17+08:00">2020-12-16</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-01-26 13:52:41" itemprop="dateModified" datetime="2021-01-26T13:52:41+08:00">2021-01-26</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/hexo/" itemprop="url" rel="index"><span itemprop="name">hexo</span></a>
        </span>
    </span>

  
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>107</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <ol>
<li><code>npm install --save hexo-deployer-git</code><br>如果出现<code>ERROR Deployer not found: git</code>报错，可以使用<code>npm install --save hexo-deployer-git</code>命令解决。</li>
</ol>

      
    </div>

    
    
    
      


    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2020/12/09/npm%E3%80%81nvm%E4%BD%BF%E7%94%A8%E5%9B%BD%E5%86%85%E6%B7%98%E5%AE%9D%E6%BA%90/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2020/12/09/npm%E3%80%81nvm%E4%BD%BF%E7%94%A8%E5%9B%BD%E5%86%85%E6%B7%98%E5%AE%9D%E6%BA%90/" class="post-title-link" itemprop="url">npm、nvm使用国内淘宝源</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-12-09 10:21:45" itemprop="dateCreated datePublished" datetime="2020-12-09T10:21:45+08:00">2020-12-09</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-01-26 13:52:41" itemprop="dateModified" datetime="2021-01-26T13:52:41+08:00">2021-01-26</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/hexo/" itemprop="url" rel="index"><span itemprop="name">hexo</span></a>
        </span>
    </span>

  
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>337</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <ul>
<li>npm：</li>
</ul>
<ol>
<li>显示当前的镜像地址：<code>npm get registry</code></li>
<li>更换为淘宝的镜像地址：<code>npm config set registry http://registry.npm.taobao.org</code></li>
<li>再次查看当前的镜像地址：<code>npm get registry</code></li>
</ol>
<ul>
<li>nvm：</li>
</ul>
<ol>
<li><code>.bash_profile</code>文件中添加：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">export NVM_NODEJS_ORG_MIRROR&#x3D;http:&#x2F;&#x2F;npm.taobao.org&#x2F;mirrors&#x2F;node</span><br><span class="line">export NVM_IOJS_ORG_MIRROR&#x3D;http:&#x2F;&#x2F;npm.taobao.org&#x2F;mirrors&#x2F;iojs</span><br></pre></td></tr></table></figure></li>
<li>执行<code>source ~/.bash_profile</code>起效</li>
</ol>

      
    </div>

    
    
    
      


    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" class="post-title-link" itemprop="url">Flutter、Dart学习总结</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-12-08 15:37:16" itemprop="dateCreated datePublished" datetime="2020-12-08T15:37:16+08:00">2020-12-08</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-01-26 13:52:41" itemprop="dateModified" datetime="2021-01-26T13:52:41+08:00">2021-01-26</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
        </span>
    </span>

  
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>6.5k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>6 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <ul>
<li><h4 id="Container"><a href="#Container" class="headerlink" title="Container"></a>Container</h4>添加 padding, margins, borders, background color, 或将其他装饰添加到widget</li>
<li><h4 id="Scaffold"><a href="#Scaffold" class="headerlink" title="Scaffold"></a>Scaffold</h4>使用Scaffold是最容易的，它是 Material Components库中的一个widget，它提供了一个默认banner，背景颜色，并且具有添加drawer，snack bar和底部sheet的API</li>
<li><h4 id="DefaultTextStyle"><a href="#DefaultTextStyle" class="headerlink" title="DefaultTextStyle"></a>DefaultTextStyle</h4>DefaultTextStyle.merge可以允许您创建一个默认的文本样式，该样式会被其所有的子节点继承</li>
<li><h4 id="maxCrossAxisExtent"><a href="#maxCrossAxisExtent" class="headerlink" title="maxCrossAxisExtent"></a>maxCrossAxisExtent</h4><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/8a142e06c48e">GridView.extent中maxCrossAxisExtent的作用</a></li>
<li><h4 id="SizedBox"><a href="#SizedBox" class="headerlink" title="SizedBox"></a>SizedBox</h4>能强制子控件具有特定宽度、高度或两者都有,使子控件设置的宽高失效<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">new SizedBox(</span><br><span class="line">  width: 100.0,</span><br><span class="line">  height: 100.0,</span><br><span class="line">  child: Container(</span><br><span class="line">    width: 200.0,</span><br><span class="line">    height: 200.0,</span><br><span class="line">    color: Color(0xffff0000),</span><br><span class="line">  ),</span><br><span class="line">)</span><br></pre></td></tr></table></figure></li>
<li><h4 id="State状态管理"><a href="#State状态管理" class="headerlink" title="State状态管理"></a>State状态管理</h4></li>
</ul>
<ol>
<li>如果状态是用户数据，如复选框的选中状态、滑块的位置，则该状态最好由父widget管理</li>
<li>如果所讨论的状态是有关界面外观效果的，例如动画，那么状态最好由widget本身来管理</li>
<li>如果有疑问，首选是在父widget中管理状态</li>
</ol>
<ul>
<li><h4 id="flutter的Key"><a href="#flutter的Key" class="headerlink" title="flutter的Key"></a>flutter的Key</h4><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/fc88c0774078">Flutter–&gt;何时需要使用到key？</a><br><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/3b2bc9f0ddd6">flutter 中的 key</a></li>
<li><h4 id="flutter的json转为实体类插件（Android-Studio插件）"><a href="#flutter的json转为实体类插件（Android-Studio插件）" class="headerlink" title="flutter的json转为实体类插件（Android Studio插件）"></a>flutter的json转为实体类插件（Android Studio插件）</h4>AS中搜索插件<code>FlutterJsonBeanFactory </code>，安装，重启AS。<br>在指定目录下，右键，new - dart bean class File From JSON，粘贴进json，格式化，生成即可。<br><img src="/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/2988687-b38ed2f78df0bcec.png" alt="2988687-b38ed2f78df0bcec.png"></li>
<li><h4 id="dart中export使用"><a href="#dart中export使用" class="headerlink" title="dart中export使用"></a>dart中export使用</h4>在A库中使用export关键字引入B库，当我们使用A库的时候，会自动引入B库，也就是说我们导入了A库，就可以使用B库了。</li>
<li><h4 id="cupertino下push的同时，隐藏tabbar"><a href="#cupertino下push的同时，隐藏tabbar" class="headerlink" title="cupertino下push的同时，隐藏tabbar"></a>cupertino下push的同时，隐藏tabbar</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Navigator.of(context, rootNavigator: true)</span><br><span class="line">          .push(CupertinoPageRoute(builder: (BuildContext context) &#123;</span><br><span class="line">        return new MsgCenterPage();</span><br><span class="line">      &#125;));</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter使用16进制色值"><a href="#flutter使用16进制色值" class="headerlink" title="flutter使用16进制色值"></a>flutter使用16进制色值</h4>Color(0xFFFF8A65)其中0x后面的两位FF表示透明度16进制，FF后面为色值</li>
<li><h4 id="flutter获取屏幕宽高和状态栏高度"><a href="#flutter获取屏幕宽高和状态栏高度" class="headerlink" title="flutter获取屏幕宽高和状态栏高度"></a>flutter获取屏幕宽高和状态栏高度</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;** 获取屏幕宽度 *&#x2F;</span><br><span class="line">  static double getScreenWidth(BuildContext context) &#123;</span><br><span class="line">    return MediaQuery.of(context).size.width;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  &#x2F;** 获取屏幕高度 *&#x2F;</span><br><span class="line">  static double getScreenHeight(BuildContext context) &#123;</span><br><span class="line">    return MediaQuery.of(context).size.height;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  &#x2F;** 获取系统状态栏高度 *&#x2F;</span><br><span class="line">  static double getSysStatsHeight(BuildContext context) &#123;</span><br><span class="line">    return MediaQuery.of(context).padding.top;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="GestureDetector为布局添加手势，child和空白区域全部可点击"><a href="#GestureDetector为布局添加手势，child和空白区域全部可点击" class="headerlink" title="GestureDetector为布局添加手势，child和空白区域全部可点击"></a>GestureDetector为布局添加手势，child和空白区域全部可点击</h4>GestureDetector的child添加为Container，同时Container要设置color，整体Container的child和空白区域才全部可点击，否则则是Container的child可点而空白不可点击。</li>
<li><h4 id="隐藏键盘"><a href="#隐藏键盘" class="headerlink" title="隐藏键盘"></a>隐藏键盘</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">FocusScope.of(context).requestFocus(FocusNode());</span><br></pre></td></tr></table></figure></li>
<li><h4 id="dynamic的使用"><a href="#dynamic的使用" class="headerlink" title="dynamic的使用"></a>dynamic的使用</h4>在数据解析过程中，如果不确定当前类型的话，可以使用dynamic来代替，具体是某个类型的话，再转为某个类型。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">@JsonSerializable()</span><br><span class="line">class ResultData extends Object &#123;</span><br><span class="line"></span><br><span class="line">  @JsonKey(name: &#39;code&#39;)</span><br><span class="line">  String code;</span><br><span class="line"></span><br><span class="line">  @JsonKey(name: &#39;data&#39;)</span><br><span class="line">  dynamic data;</span><br><span class="line"></span><br><span class="line">  @JsonKey(name: &#39;url&#39;)</span><br><span class="line">  String url;</span><br><span class="line"></span><br><span class="line">  @JsonKey(name: &#39;message&#39;)</span><br><span class="line">  String message;</span><br><span class="line"></span><br><span class="line">  ResultData(this.code,this.data,this.url,this.message,);</span><br><span class="line"></span><br><span class="line">  factory ResultData.fromJson(Map&lt;String, dynamic&gt; srcJson) &#x3D;&gt; _$ResultDataFromJson(srcJson);</span><br><span class="line"></span><br><span class="line">  Map&lt;String, dynamic&gt; toJson() &#x3D;&gt; _$ResultDataToJson(this);</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter延迟执行"><a href="#flutter延迟执行" class="headerlink" title="flutter延迟执行"></a>flutter延迟执行</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">new Future.delayed(Duration(seconds: 2), () &#123;</span><br><span class="line">        Navigator.of(context).pop();</span><br><span class="line">      &#125;);</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter中url中编码解码"><a href="#flutter中url中编码解码" class="headerlink" title="flutter中url中编码解码"></a>flutter中url中编码解码</h4>例如：需要将<br><code>js://iOSAction?%7B%22method%22:%22toLogin%22%7D</code><br>转为<br><code>js://iOSAction?&#123;&quot;method&quot;:&quot;toLogin&quot;&#125;</code><br>使用Uri的decode方法：<br><code>String url = Uri.decodeFull(navigation.url);</code><br>相反，编码的话，使用Uri的encode方法。</li>
<li><h4 id="flutter的图片布局填充满父布局"><a href="#flutter的图片布局填充满父布局" class="headerlink" title="flutter的图片布局填充满父布局"></a>flutter的图片布局填充满父布局</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">方法一：</span><br><span class="line">new ConstrainedBox(</span><br><span class="line">                  constraints: new BoxConstraints.expand(),</span><br><span class="line">                  child: new FadeInImage.assetNetwork(</span><br><span class="line">                    placeholder: &quot;assets&#x2F;home&#x2F;placeholder_default.png&quot;,</span><br><span class="line">                    image: model !&#x3D; null</span><br><span class="line">                        ? &quot;$&#123;APIConfig.pictureURL&#125;&quot;</span><br><span class="line">                        &quot;$&#123;model.pictureUrl&#125;&quot;</span><br><span class="line">                        : null,</span><br><span class="line">                    fit: BoxFit.fill,</span><br><span class="line">                  ),</span><br><span class="line">                ),</span><br><span class="line"></span><br><span class="line">方法二：</span><br><span class="line">如果已知宽高，Image里直接定义指定的宽和高</span><br><span class="line">MediaQuery.of(context).size.width</span><br><span class="line">MediaQuery.of(context).size.height</span><br></pre></td></tr></table></figure></li>
<li><h4 id="Text超出省略号截断"><a href="#Text超出省略号截断" class="headerlink" title="Text超出省略号截断"></a>Text超出省略号截断</h4><code>TextOverflow.ellipsis</code><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">new Text(</span><br><span class="line">                  &#39;我爱北京天安门，我爱北京天安门，我爱北京天安门，我爱北京天安门，我爱北京天安门，我爱北京天安门，我爱北京天安门&#39;,</span><br><span class="line">                  overflow: TextOverflow.ellipsis,</span><br><span class="line">                ),</span><br></pre></td></tr></table></figure></li>
<li><h4 id="list通过map转化的时候获取index"><a href="#list通过map转化的时候获取index" class="headerlink" title="list通过map转化的时候获取index"></a><code>list</code>通过<code>map</code>转化的时候获取<code>index</code></h4><code>list</code>通过<code>asMap</code>转为<code>Map</code>，然后使用<code>Map.map</code>获取<code>index</code>。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">homeNoticeList</span><br><span class="line">    .asMap()</span><br><span class="line">    .map((index, model) &#x3D;&gt; MapEntry(</span><br><span class="line">          index,</span><br><span class="line">          new GestureDetector(</span><br><span class="line">            onTap: () &#123;</span><br><span class="line">              logPrint(index, message: &quot;我点击了滚动的广告&quot;);</span><br><span class="line">            &#125;,</span><br><span class="line">            child: new Container(</span><br><span class="line">              color: ColorConfig.white,</span><br><span class="line">              child: new Align(</span><br><span class="line">                alignment: Alignment.centerLeft,</span><br><span class="line">                child: new Text(</span><br><span class="line">                  model.title,</span><br><span class="line">                  style: new TextStyle(fontSize: 14.0),</span><br><span class="line">                  overflow: TextOverflow.ellipsis,</span><br><span class="line">                ),</span><br><span class="line">              ),</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        ))</span><br><span class="line">    .values</span><br><span class="line">    .toList();</span><br></pre></td></tr></table></figure></li>
<li><h4 id="Cookie管理"><a href="#Cookie管理" class="headerlink" title="Cookie管理"></a><code>Cookie</code>管理</h4>网络请求使用dio进行网络请求，可以添加cookiemanager拦截器，来对cookie进行自动管理，也可手动删除cookie。<br>Flutter中添加依赖<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">dio: ^2.1.7 # 网络请求</span><br><span class="line">cookie_jar: ^1.0.0 # cookie管理</span><br></pre></td></tr></table></figure>
dio请求封装中，添加拦截器：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 添加&#96;Cookie&#96;管理</span><br><span class="line">    dio.interceptors.add(CookieManager(CookieJar()));</span><br></pre></td></tr></table></figure>
然后在<code>request</code>的<code>headers</code>中会自动增加<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cookie: SESSION&#x3D;9d41c3e9-5619-492f-aa92-d85add6b04ed</span><br></pre></td></tr></table></figure>
与<code>iOS</code>的<code>moya</code> <code>cookie</code>不一样，一个是<code>cookie</code>，一个是<code>&quot;Set-Cookie&quot;</code>（header中拼入）：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[&quot;Set-Cookie&quot;:SESSION&#x3D;9d41c3e9-5619-492f-aa92-d85add6b04ed]</span><br></pre></td></tr></table></figure></li>
<li><h4 id="Appbar中使用自定义的返回按钮"><a href="#Appbar中使用自定义的返回按钮" class="headerlink" title="Appbar中使用自定义的返回按钮"></a><code>Appbar</code>中使用自定义的返回按钮</h4>先设置<code>automaticallyImplyLeading</code>为<code>false</code>，然后在<code>leading</code>中设置返回按钮。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">automaticallyImplyLeading: false,</span><br><span class="line">        leading: new GestureDetector(</span><br><span class="line">          onTap: () &#123;</span><br><span class="line">            Navigator.of(context).pop();</span><br><span class="line">          &#125;,</span><br><span class="line">          child: new Image.asset(&#39;assets&#x2F;common&#x2F;nav_back_arrow.png&#39;),</span><br><span class="line">        ),</span><br></pre></td></tr></table></figure></li>
<li><h4 id="设置appbar高度"><a href="#设置appbar高度" class="headerlink" title="设置appbar高度"></a>设置appbar高度</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">appBar: new PreferredSize(</span><br><span class="line">        child: appBar,</span><br><span class="line">        preferredSize: Size.fromHeight(44),</span><br><span class="line">      ),</span><br></pre></td></tr></table></figure></li>
<li><h4 id="使用webview-flutter时执行调用js的方法："><a href="#使用webview-flutter时执行调用js的方法：" class="headerlink" title="使用webview_flutter时执行调用js的方法："></a>使用<code>webview_flutter</code>时执行调用<code>js</code>的方法：</h4>推荐在<code>onPageFinished</code>里调用。<br>例如：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">onPageFinished: (String url) &#123;</span><br><span class="line">                      print(&quot;page finished loading: $url&quot;);</span><br><span class="line">                      setState(() &#123;</span><br><span class="line">                        isLoading &#x3D; false;</span><br><span class="line">                      &#125;);</span><br><span class="line"></span><br><span class="line">                      &#x2F;&#x2F; 如果为项目风险等级的url，则执行隐藏header的js。</span><br><span class="line">                      if (widget.url &#x3D;&#x3D; ContentConfig.projectRiskLevel) &#123;</span><br><span class="line">                        _controller.future.then((controller) &#123;</span><br><span class="line">                          controller</span><br><span class="line">                              .evaluateJavascript(&#39;hideHeader();&#39;)</span><br><span class="line">                              .then((result) &#123;&#125;);</span><br><span class="line">                        &#125;);</span><br><span class="line">                      &#125;</span><br><span class="line">                    &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="android-studio中使用print打印，只能打印出一部分的解决办法："><a href="#android-studio中使用print打印，只能打印出一部分的解决办法：" class="headerlink" title="android studio中使用print打印，只能打印出一部分的解决办法："></a><code>android studio</code>中使用<code>print</code>打印，只能打印出一部分的解决办法：</h4>导入<code>foundation</code>库：<br><code>import &#39;package:flutter/foundation.dart&#39;;</code><br>使用<code>flutter</code>里<code>foundation</code>中的<code>debugPrint</code>打印即可打印全部。</li>
<li><h4 id="TabBar对应的TabController使用代码切换tabBar-index从0开始-："><a href="#TabBar对应的TabController使用代码切换tabBar-index从0开始-：" class="headerlink" title="TabBar对应的TabController使用代码切换tabBar (index从0开始)："></a>TabBar对应的TabController使用代码切换tabBar (index从0开始)：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">controller.animateTo(index);</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter富文本RichText使用"><a href="#flutter富文本RichText使用" class="headerlink" title="flutter富文本RichText使用"></a>flutter富文本RichText使用</h4><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/c4ee2a7a97d2">RichText在段落中显示不同样式</a></li>
<li><h4 id="复制到粘贴板"><a href="#复制到粘贴板" class="headerlink" title="复制到粘贴板"></a>复制到粘贴板</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">import &#39;package:flutter&#x2F;services.dart&#39;;</span><br><span class="line"></span><br><span class="line">  static copyToClipboard(final String text) &#123;</span><br><span class="line">    if (text &#x3D;&#x3D; null) return;</span><br><span class="line">    Clipboard.setData(new ClipboardData(text: text));</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="返回当前的时间戳"><a href="#返回当前的时间戳" class="headerlink" title="返回当前的时间戳"></a>返回当前的时间戳</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">static int currentTimeMillis() &#123;</span><br><span class="line">    return new DateTime.now().millisecondsSinceEpoch;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="返回文件大小字符串"><a href="#返回文件大小字符串" class="headerlink" title="返回文件大小字符串"></a>返回文件大小字符串</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">static const RollupSize_Units &#x3D; [&quot;GB&quot;, &quot;MB&quot;, &quot;KB&quot;, &quot;B&quot;];</span><br><span class="line">  &#x2F;** 返回文件大小字符串 *&#x2F;</span><br><span class="line">  static String getRollupSize(int size) &#123;</span><br><span class="line">    int idx &#x3D; 3;</span><br><span class="line">    int r1 &#x3D; 0;</span><br><span class="line">    String result &#x3D; &quot;&quot;;</span><br><span class="line">    while (idx &gt;&#x3D; 0) &#123;</span><br><span class="line">      int s1 &#x3D; size % 1024;</span><br><span class="line">      size &#x3D; size &gt;&gt; 10;</span><br><span class="line">      if (size &#x3D;&#x3D; 0 || idx &#x3D;&#x3D; 0) &#123;</span><br><span class="line">        r1 &#x3D; (r1 * 100) ~&#x2F; 1024;</span><br><span class="line">        if (r1 &gt; 0) &#123;</span><br><span class="line">          if (r1 &gt;&#x3D; 10)</span><br><span class="line">            result &#x3D; &quot;$s1.$r1$&#123;RollupSize_Units[idx]&#125;&quot;;</span><br><span class="line">          else</span><br><span class="line">            result &#x3D; &quot;$s1.0$r1$&#123;RollupSize_Units[idx]&#125;&quot;;</span><br><span class="line">        &#125; else</span><br><span class="line">          result &#x3D; s1.toString() + RollupSize_Units[idx];</span><br><span class="line">        break;</span><br><span class="line">      &#125;</span><br><span class="line">      r1 &#x3D; s1;</span><br><span class="line">      idx--;</span><br><span class="line">    &#125;</span><br><span class="line">    return result;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter调起拨打电话"><a href="#flutter调起拨打电话" class="headerlink" title="flutter调起拨打电话"></a>flutter调起拨打电话</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">import &#39;package:url_launcher&#x2F;url_launcher.dart&#39;;</span><br><span class="line"></span><br><span class="line">Future&lt;void&gt; _launched;</span><br><span class="line"></span><br><span class="line">Future&lt;void&gt; _makePhoneCall(String url) async &#123;</span><br><span class="line">    if (await canLaunch(url)) &#123;</span><br><span class="line">      await launch(url);</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">      throw &#39;Could not launch $url&#39;;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 调起拨打电话</span><br><span class="line">          setState(() &#123;</span><br><span class="line">            _launched &#x3D; _makePhoneCall(&#39;tel:18612345678&#39;);</span><br><span class="line">          &#125;);</span><br></pre></td></tr></table></figure></li>
<li><h4 id="垂直分割线"><a href="#垂直分割线" class="headerlink" title="垂直分割线"></a>垂直分割线</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Container(</span><br><span class="line">                  height: 40,</span><br><span class="line">                  child: VerticalDivider(color: Colors.red),</span><br><span class="line">                ),</span><br></pre></td></tr></table></figure></li>
<li><h4 id="可取消的定时任务"><a href="#可取消的定时任务" class="headerlink" title="可取消的定时任务"></a>可取消的定时任务</h4>Timer代替Future.</li>
</ul>

      
    </div>

    
    
    
      


    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>






<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2020 – 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yuanzhiying</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">16k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">14 分钟</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/@next-theme/pjax@0.4.0/pjax.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '.page-configurations',
    '.main-inner',
    '.post-toc-wrap',
    '.languages',
    '.pjax'
  ],
  analytics: false,
  cacheBust: false,
  scrollRestoration: false,
  scrollTo: !CONFIG.bookmark.enable
});

document.addEventListener('pjax:success', () => {
  pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  const hasTOC = document.querySelector('.post-toc');
  document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC);
  document.querySelector(hasTOC ? '.sidebar-nav-toc' : '.sidebar-nav-overview').click();
  NexT.utils.updateSidebarPosition();
});
</script>


  

<script src="/js/local-search.js"></script>






  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




    <div class="pjax">


    </div>
</body>
</html>
